package com.gitee.zwj;

import com.gitee.zwj.codegen.SqlBaseBaseVisitor;
import com.gitee.zwj.codegen.SqlBaseParser;

import java.util.ArrayList;
import java.util.List;


public class TableAndColumnExtractor extends SqlBaseBaseVisitor {

    private List<String> tableNames;

    private List<String> columnNames;

    public TableAndColumnExtractor() {
        tableNames = new ArrayList<>();
        columnNames = new ArrayList<>();
    }

    public List<String> getTableNames() {
        return tableNames;
    }

    public List<String> getColumnNames() {
        return columnNames;
    }

    @Override
    public String visitTableIdentifier(SqlBaseParser.TableIdentifierContext ctx) {
        String tableName = ctx.getChild(0).getText();
        tableNames.add(tableName);
        return tableName;
    }

    @Override
    public String visitColumnReference(SqlBaseParser.ColumnReferenceContext ctx) {
        String columnName = ctx.getChild(0).getText();
        columnNames.add(columnName);
        return columnName;
    }
}
